#ifndef RECOLORING_H
#define RECOLORING_H

#include<QColor>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <math.h>
#include<QObject>
//#include<opencv2/contrib/contrib.hpp>
using namespace cv;
using namespace std;
class Recoloring:public QObject
{
    Q_OBJECT
public:
    Recoloring();
    double*center;
    double*changed_center;
    void init(Mat img);
    Mat test();
signals:
    void sendShit(Mat shit);
public slots:
    void Shit(const QColor&color,int id);
private:
    Mat image;
    Mat imaging;//没有初始化
    int centersize = 5;
    double RBF_param_coff = 5.0;
    int ngrid = 10;
    int grid_size;
    double **grid_lab;
    double*ori_b, *ori_g, *ori_r;
    double*res_b, *res_g, *res_r, *mask;
    double*grid_R, *grid_G, *grid_B;
    int**weightindex;
    double**weightmap;
    int*IndexSortOrder;

    void onload();
    void prepare_grid();
    double* RGB2LAB(double*Q);
    double* LAB2RGB(double*Q);
    double* Multi(double**A, int ma, double*B);
    double* calculate_singlegrid(double ori_r, double ori_g, double ori_b);
    double CalculateLABDistance(double l1, double a1, double b1,
        double l2,double a2, double b2);
    bool Bigchange(double*dir);
    bool OutBoundary(double*testrgb);
    double FindBoundary(double*vsrc, double* dir, double l, double r);
    double *CalculateSinglePoint(double param, int matrixsize,
        double*oldpalette_L, double*oldpalette_A, double* oldpalette_B,
        double*diffpalette_L, double*diffpalette_A, double*diffpalette_B,
        double*vsrc);
    void CalculateGridResult(int palette_size,
        double*oldpalette_L, double*oldpalette_A, double*oldpalette_B,
        double*diffpalette_L, double*diffpalette_A, double*diffpalette_B);
    double SmoothL(double x,double d);
    void drawRes(double*input_palette, double* output_palette, int palette_size);
    void drawImage();

    double * k_means(Mat image, int center_num);
};


#endif // RECOLORING_H
